#pragma once

#include "UseCase.h"

#include "Classifier.h"
#include "Extend.h"
#include "ExtensionPoint.h"
#include "Include.h"

namespace uml {

UseCase::UseCase(const QString& umlType)
    : Classifier(umlType) {}

void UseCase::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Classifier::fromJson(json, errorList);
    BehavioredClassifier::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(extends_, "extends", json, errorList);
    JsonSerializable::fromJsonArray(extensionPoints_, "extensionPoints", json, errorList);
    JsonSerializable::fromJsonArray(includes_, "includes", json, errorList);
    JsonSerializable::fromJsonArray(subjects_, "subjects", json, errorList);
}

void UseCase::toJson(QJsonObject& json) {
    Classifier::toJson(json);
    BehavioredClassifier::toJson(json);
    JsonSerializable::toJsonArray(extends_, "extends", json);
    JsonSerializable::toJsonArray(extensionPoints_, "extensionPoints", json);
    JsonSerializable::toJsonArray(includes_, "includes", json);
    JsonSerializable::toJsonArray(subjects_, "subjects", json);
}

/// <summary>
/// allIncludedUseCases
    /// The query allIncludedUseCases() returns the transitive closure of all UseCases
    /// (directly or indirectly) included by this UseCase.
/// </summary>
    /// <code>
    /// result = (self.include.addition->union(self.include.addition->collect(uc | uc.allIncludedUseCases()))->asSet())
    /// </code>
shared_ptr<vector<UseCase>> UseCase::allIncludedUseCases() const
{
    return nullptr;
}

/// <summary>
/// extends getter
/// The Extend relationships owned by this UseCase.
/// </summary>
vector<shared_ptr<Extend>>& UseCase::extends() {
    return extends_;
}

/// <summary>
/// extensionPoints getter
/// The ExtensionPoints owned by this UseCase.
/// </summary>
vector<shared_ptr<ExtensionPoint>>& UseCase::extensionPoints() {
    return extensionPoints_;
}

/// <summary>
/// includes getter
/// The Include relationships owned by this UseCase.
/// </summary>
vector<shared_ptr<Include>>& UseCase::includes() {
    return includes_;
}

/// <summary>
/// subjects getter
/// The subjects to which this UseCase applies. Each subject or its parts realize
/// all the UseCases that apply to it.
/// </summary>
vector<shared_ptr<Classifier>>& UseCase::subjects() {
    return subjects_;
}

} // namespace uml
